

package com.maoshi.shop.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.maoshi.shop.bean.app.dto.NoticeDto;
import com.maoshi.shop.bean.model.Notice;
import com.maoshi.shop.dao.NoticeMapper;
import com.maoshi.shop.service.NoticeService;
import lombok.AllArgsConstructor;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 公告管理
 *
 * @author hzm
 * @date 2019-04-18 21:21:40
 */
@Service
@AllArgsConstructor
public class NoticeServiceImpl extends ServiceImpl<NoticeMapper, Notice> implements NoticeService {

    private NoticeMapper noticeMapper;

    @Override
    @Cacheable(cacheNames = "notices", key = "#shopId")
    public List<Notice> listTopNoticeByShopId(Long shopId) {
        return noticeMapper.selectList(new LambdaQueryWrapper<Notice>()
                .eq(Notice::getStatus, 1)
                .eq(Notice::getIsTop, 1)
                .eq(Notice::getShopId, shopId)
                .orderByDesc(Notice::getPublishTime));
    }

    @Override
    @CacheEvict(cacheNames = "notices", key = "#shopId")
    public void removeTopNoticeListCacheByShopId(Long shopId) {
    }

    @Override
    public Page<NoticeDto> pageNotice(Page<NoticeDto> page, Long shopId) {
        return noticeMapper.pageNotice(page, shopId);
    }

    @Override
    @Cacheable(cacheNames = "notice", key = "#noticeId")
    public Notice getNoticeById(Long noticeId) {
        return noticeMapper.selectById(noticeId);
    }

    @Override
    @CacheEvict(cacheNames = "notice", key = "#noticeId")
    public void removeNoticeCacheById(Long noticeId) {
    }

    @Override
    public void removeByIdAndShopId(Long id, long shopId) {
        noticeMapper.removeByIdAndShopId(id,shopId);
    }


}
